package com.yjd.bi.statistic.control;

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yjd.bi.comm.utils.BiDateUtil;
import com.yjd.bi.jf.service.IJfIntegralService;
import com.yjd.comm.annotation.DateString;
import com.yjd.comm.annotation.ServiceRemoteProxy;
import com.yjd.comm.base.control.BaseControl;
import com.yjd.comm.rpm.RpmServiceKeyEnum;
import com.yjd.comm.util.DateUtil;
import com.yjd.comm.util.FrameUtil;
import com.yjd.comm.util.ServletUtil;

@Controller
@Scope("prototype")
@RequestMapping("jf")
public class JFControl  extends BaseControl {
	@ServiceRemoteProxy(serviceUrlResouceKey = RpmServiceKeyEnum.RPM_BI_SERVICE_KEY)
	private IJfIntegralService jfIntegralService;
	
	@RequestMapping("index")
	public String index() throws Exception {
        request.setAttribute("start", "2017-04-01");
        request.setAttribute("end", BiDateUtil.initBiDate());
        return "jf.index";
	}
	
	@RequestMapping("summary")
	public void summary(@DateString String start, @DateString String end)
			throws Exception {
		Map<String, Object> paramMap = ServletUtil.getParameterMap(request);
		paramMap.put("start", FrameUtil.getTime(DateUtil.parseDate(start,
				DateUtil.PATTERN_yyyyMMdd)));
		paramMap.put("end", FrameUtil.getTime(DateUtil.parseDate(end,
				DateUtil.PATTERN_yyyyMMdd))+23*60*60+59*61);
		Map<String, Integer> resultMap = new HashMap<String, Integer>();
		// 总获得积分
		paramMap.put("propertyName", "total_point");
		resultMap.put("total_point",
				jfIntegralService.getSummary(paramMap));
		//APP签到总积分
		paramMap.put("propertyName", "appsign_point");
		resultMap.put("appsign_point",
				jfIntegralService.getSummary(paramMap));
		//微站签到总积分
		paramMap.put("propertyName", "wapsign_point");
		resultMap.put("wapsign_point",
				jfIntegralService.getSummary(paramMap));
		//PC签到总积分
		paramMap.put("propertyName", "pcsign_point");
		resultMap.put("pcsign_point",
				jfIntegralService.getSummary(paramMap));
		//投资获得总积分
		paramMap.put("propertyName", "invest_point");
		resultMap.put("invest_point",
				jfIntegralService.getSummary(paramMap));
		//总消耗积分
		paramMap.put("propertyName", "cost_point");
		resultMap.put("cost_point",
				jfIntegralService.getSummary(paramMap));
		//总过期积分
		paramMap.put("propertyName", "passed_point");
		resultMap.put("passed_point",
				jfIntegralService.getSummary(paramMap));
		//APP签到人数
		paramMap.put("propertyName", "appsign_count");
		resultMap.put("appsign_count",
				jfIntegralService.getSummary(paramMap));
		//微站签到人数
		paramMap.put("propertyName", "wapsign_count");
		resultMap.put("wapsign_count",
				jfIntegralService.getSummary(paramMap));
		//PC签到人数
		paramMap.put("propertyName", "pcsign_count");
		resultMap.put("pcsign_count",
				jfIntegralService.getSummary(paramMap));
		super.successData(resultMap);
	}
}
